﻿@{
    Layout = "~/Views/Shared/OA/_Index.cshtml";
}
@section Toolbar
{
    @if (!string.IsNullOrEmpty(Request["RoleId"]))
    {
        @Html.MyNet().Button(new ButtonOptions { Text = "返回", Click = "back" })
    }
    @Html.MyNet().Button(new ButtonOptions { Text = "新建", Click = "create" })
    @Html.MyNet().Button(new ButtonOptions { Text = "启用", Click = "enable" })
    @Html.MyNet().Button(new ButtonOptions { Text = "禁用", Click = "disable" })
    @Html.MyNet().Button(new ButtonOptions { Text = "解锁", Click = "unlock" })
    @Html.MyNet().Button(new ButtonOptions { Text = "删除", Click = "removee", Icon = "remove" })
}
@section Menu
{
    @Html.MyNet().Menu(new ButtonOptions { Text = "修改", Click = "modify" })
    @Html.MyNet().Menu(new ButtonOptions { Text = "启用", Click = "enable" })
    @Html.MyNet().Menu(new ButtonOptions { Text = "禁用", Click = "disable" })
    @Html.MyNet().Menu(new ButtonOptions { Text = "解锁", Click = "unlock" })
    @Html.MyNet().Menu(new ButtonOptions { Text = "重置密码", Click = "resetPassword", Icon = "pasword" })
    @Html.MyNet().Menu(new ButtonOptions { Text = "设置角色", Click = "rolee", Icon = "role" })
    @Html.MyNet().Menu(new ButtonOptions { Text = "删除", Click = "removee", Icon = "remove" })
}
@section Query
{
    @Html.Partial("_Query", new UserCondition())
}
@section Main
{
    <div id="grid" class="grid">
    </div>
    <div id="pager" class="pager">
    </div>
}
@Html.Hidden("ForApplication", Request["Application"])
@Html.Hidden("RoleId", Request["RoleId"])

<script>
    var application = $("#ForApplication").val();
    var roleId = $("#RoleId").val();

    var url = "/Common/User/";

    jQuery(function () {
        read();
    });

    function read() {
        query.application = application;
        query.roleId = roleId;
        $.ajax
        ({
            url: url + "Read",
            data: query,
            type: "post",
            error: disposeError,
            success: function (result) {
                if (disposeException(result)) return;
                bind(result);
            }
        });
    }

    function create() {
        nav(url + "Create?Application=" + application);
    }

    function modify() {
        if (!gridSelected()) return alert("未选中任何数据！");
        nav(url + "Modify?Id=" + gridSelected()[0] + "&Application=" + application);
    }

    function removee() {
        if (!gridSelected()) return alert("未选中任何数据！");
        if (!confirm("确定要删除选中的数据吗？")) return;

        $.ajax
        ({
            url: url + "Remove",
            data: { ids: gridSelected() },
            type: "post",
            error: disposeError,
            success: function (result) {
                if (disposeException(result)) return;
                read();
            }
        });
    }

    function resetPassword() {
        if (!gridSelected()) return alert("未选中任何数据！");
        nav(url + "ResetPassword?Id=" + gridSelected()[0]);
    }

    function rolee() {
        if (!gridSelected()) return alert("未选中任何数据！");
        nav(url + "Role?Id=" + gridSelected()[0] + "&Application=" + application);
    }

    function enable() {
        if (!gridSelected()) return alert("未选中任何数据！");

        $.ajax
        ({
            url: url + "Enable",
            data: { ids: gridSelected() },
            type: "post",
            error: disposeError,
            success: function (result) {
                if (disposeException(result)) return;

                read();
            }
        });
    }

    function disable() {
        if (!gridSelected()) return alert("未选中任何数据！");

        $.ajax
        ({
            url: url + "Disable",
            data: { ids: gridSelected() },
            type: "post",
            error: disposeError,
            success: function (result) {
                if (disposeException(result)) return;
                read();
            }
        });
    }

    function unlock() {
        if (!gridSelected()) return alert("未选中任何数据！");

        $.ajax
        ({
            url: url + "UnlockOut",
            data: { ids: gridSelected() },
            type: "post",
            error: disposeError,
            success: function (result) {
                if (disposeException(result)) return;
                read();
            }
        });
    }

</script>
